<script type="text/javascript">
//表单验证
function peijian_submit() {
    var pjsl = $("input[name='accessory_quantity']").val();
    var pjkcsl = $("input[name='quantity']").val();
    if(!pjsl || pjsl==0){
        alert('<?=lang('peijian_yzpjsl')?>');
        return false;
    }
    if(parseInt(pjsl) > parseInt(pjkcsl)){
        alert('<?=lang('peijian_pjsldykcsl')?>');
        return false;
    }
	return true;
}
$(function(){
    $('#search input[name="accessory_name"]').keyup(function(){
        if($(this).val()==""){
            $('#search_auto').css('display', 'none')
        }else {
            $.post("<?=blang_url('ajax/ajax/ajaxMaterial')?>", {
                'keyword': $(this).val(),
                'mtid': $('#mtid').val(),
                'productId':<?=$productId?>
            }, function (data) {
                if (data == '0') {
                    $("input[name='isno']").val(0);
                    var str = "<div style='width: 800px;text-align: center;background-color:#d3d3d3'>" +
                        "<?=lang('pcm_jsbd')?> <br><input type='button' onclick='rilegou(1)' value='<?=lang('pcm_y')?>'>" +
                        "&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' onclick='rilegou(0)' value='<?=lang('pcm_n')?>'></div>";
                    $('#search_auto').html(str).css('display', 'block');
                } else {
//                    $("input[name='sku']").val('');
//                    $("input[name='accessory_price']").val('');
//                    $("input[name='accessory_cost']").val(''));
//                    $("input[name='purchase_source']").val('');
                    $("input[name='isno']").val(1);
                    $('#search_auto').html(data).css('display', 'block');
                }
            });
        }
    });
    //$('#search input[name="accessory_name"]').blur(function(){
    //    $("#search_auto").css({'display':'none'});
    //});
})
function rilegou(st){
    if(st==1){
        var sts=$("input[name='accessory_name']").val();
        $("input[name='name_cn']").val(sts);
        $('#loadingDiv').css('display','block');
        $('#mjieguo').css('display','block');
        $('#yjieguo').css('display','none');
        $('#popup').slideDown();
        $(document).on('click','a',function(){
            if($(this).text()=="确定" || $(this).text()=="Determine"){
                var mdval=$('#mjieguo').css('display');
                if($("#pingpai").val()=='' && mdval=='block'){
                    alert("<?=lang('pcm_ppbnwk')?>");
                    return false;
                }
                if($("#xinghao").val()=='' && mdval=='block'){
                    alert("<?=lang('pcm_xhbnwk')?>");
                    return false;
                }
                if($("#yanse").val()=='' && mdval=='block'){
                    alert("<?=lang('pcm_ysbnwk')?>");
                    return false;
                }
                if($("#number2").val()=='' && mdval=='block'){
                    alert("<?=lang('pcm_slbnwk')?>");
                    return false;
                }
                if(isNaN($("#number2").val())){
                    alert("<?=lang('pcm_slbxssz')?>");
                    return false;
                }
                $("#caigou2").submit();
            }else{
                $('#loadingDiv').css('display','none');
                $('#popup').slideUp();
            }
        });
        $('#search_auto').css('display','none');
    }else{
        $('#search_auto').css('display','none');
    }
}
</script>

<style>
    #search{font-size:14px;}
    #search input{padding:2px 1px; width:600px; height: 24px;}
    #search_auto{
        border:1px solid #817FB2; position:absolute;display:none;
        width:800px; max-height: 420px; overflow:auto;padding-top: 5px;
    }
    #search_auto li{background:#FFF; text-align:left;}
    #search_auto li a{display:block; padding:4px 5px; cursor:pointer; color:#666;}
    #search_auto li a:hover{background:#D8D8D8; text-decoration:none; color:#000;}
    #popup{
        position: absolute;display:none; z-index:3000; background-color:#FFF; left: 450px; top: 150px; height: 400px; width: 400px;
        border: 1px solid #009ff1;
    }
    #embedding{
        position: absolute; background-color: #1aa8f4; top: 344px;height:56px; width:400px;line-height:56px;text-align:center;
    }
    #tanchu{
        text-decoration:none;
        font-family:"微软雅黑";
        font-size:30px;
        color:#FFF;
    }
</style>


<!--top结束-->
<div class="mian">
	<div class="mian1">
		<div class="mian2">
            <!--left start-->
            <?php $this->load->view('defaults/common/left');?>
            <!--left end-->
			<!--right start-->
			<div class="right">
                <!--breadcrumb start-->
                <div class="righta"><?=$this->breadcrumb->generateHTML();?> <span style="color: red">(<?=lang('pcm_hsbsmyck')?>)</span></div>
                <!--breadcrumb end-->
				<!-- contents start -->
				<div id="contents">
                    <!-- 4列表展示开始List start -->
                    <div class="ct_content">
                        <table class="c_c_tables tbwd800" cellspacing="0">
                            <thead>
                            <tr>
                                <th>sku</th>
                                <th><?=lang('product_wlmc')?></th>
                                <th><?=lang('product_wlsl')?></th>
                                <th><?=lang('product_wljg')?></th>
                                <th><?=lang('product_tjr')?></th>
                                <th><?=lang('product_tjrq')?></th>
                                <th><?=lang('public_cz')?></th>
                            </tr>
                            </thead>
                            <?php if($show_pages):?>
                                <tfoot>
                                <tr><th colspan="7" height="45"><?=$show_pages?> </th></tr>
                                </tfoot>
                            <?php endif;?>
                            <tbody>
                            <?php foreach ($wuliaoList as $key=>$rs):?>
                                <tr <?=$caofeini[$rs['id']]=='yes'?"style='color: red'":""?>>
                                    <td><?=$rs['sku']?></td>
                                    <td title="<?=$rs['accessory_name']?>" width="30%"><?=$rs['accessory_name']?>....</td>
                                    <td><?=$rs['accessory_quantity']?></td>
                                    <td><?=$rs['accessory_price']?>&nbsp;<?=$rs['accessory_currency']?></td>
                                    <td><?=$rs['add_user']?></td>
                                    <td><?=$rs['add_time']?></td>
                                    <td>
                                        <a href="<?=blang_url('products/product/del_peijian/'.$rs['id'].'/'.$rs['pid'].'/'.$mtid)?>" onclick="return confirm('<?=lang('public_isdel')?>')" ><?=lang('peijian_scpj')?></a>
                                    </td>
                                </tr>
                            <?php endforeach;?>
                            </tbody>
                        </table>
                    </div>
                    <!-- 4列表展示开始List end -->


					<div id="contents_container" style="margin-top:15px; ">
					<form action="<?=blang_url('products/product/'.$post_type)?>" method="post" name="peijianForm" onsubmit="return peijian_submit()" autocomplete="off" >
						<table cellpadding="0" cellspacing="0" id="table_forms" border="1">
                            <tr>
                                <th class="forms_left"> <?=lang('pcm_pjmc')?>:</td>
                                <td>
                                    <div id="search">
                                       <input style="width: 796px" name="accessory_name" placeholder="<?=lang('peijian_qsrpjmc')?>"/>
                                    </div>
                                    <div id="search_auto" style="margin-top: -2px;"></div>
                                </td>
                            </tr>
                            <tr>
                                <th class="forms_left">sku:</td>
                                <td>
                                    <input type="text" name="sku" readonly />
                                    <input type="hidden" id="mtid" name="mtid" value="<?=$mtid?>">
                                    <input type="hidden" id="cucy" name="cucy" value="<?=$mtid?>">
                                    <input type="hidden" id="products_cost" name="products_cost" value="<?=$mtid?>">
                                </td>
                            </tr>
                            <tr>
                                <th class="forms_left"><?=lang('pcm_pjcksl')?>:</td>
                                <td>
                                    <input type="text" name="quantity" readonly />
                                </td>
                            </tr>
                            <tr>
                                <th class="forms_left"><span>*</span><?=lang('peijian_sl')?>:</td>
                                <td>
                                    <input type="text" name="accessory_quantity" onkeyup="value=value.replace(/[^\d]/g,'')" />
                                </td>
                            </tr>
                            <tr>
                                <th class="forms_left"><?=lang('peijian_jg')?>:</td>
                                <td><input type="text" name="accessory_price"  readonly />&nbsp;<span id="currency"></span></td>
                            </tr>
                            <!--<tr>
                                <th class="forms_left"><?/*=lang('pcm_pjcbj')*/?>:</td>
                                <td><input type="text" name="accessory_cost"  readonly />&nbsp;RMB</td>
                            </tr>-->
						    <tr>
						      <td align="center" colspan="2" class="sub_padding_right">
                                  <input type="hidden" name="pid" value="<?=$peijianData['pid']?>" />
                                  <input type="hidden" name="wid"  />
                                  <input type="hidden" name="wxdh" value="<?=$mtid?>"/>
								<input type="submit" value="<?=lang('peijian_tjpj')?>" name="submits" />
						      </td>
						    </tr>
					   </table>
					</form>
				   </div>
				</div>
				<!-- contents end -->
			</div>
			<!--right end-->
		</div>
	</div>
</div>
<div id="loadingDiv" style="position:fixed;display:none;z-index:2000;top:0px;left:0px;width:100%;height:100%;background-color:rgba(224,224,224,0.5)"></div>
<div id="popup">
    <input type="hidden" id="isno" name="isno">
    <div id="yjieguo" style="margin:0px auto; margin-top: 10px; width: 350px; height: 300px;display: none">
        <h1 style="margin-left: 20px;"><?=lang('pcm_kcbz')?></h1>
    <form action="<?=blang_url('products/material/addmaterial/'.$peijianData['pid'].'/'.$mtid)?>" method="post" id="caigou1" name="caigou1">
        <table style="width: 300px;height: 250px;" border="0">
            <tr>
                <td align="right">sku：</td><td align="center"><input type="text" id="sku" name="sku" readonly></td>
            </tr>
            <tr>
                <td align="right"><?=lang('pcm_zwmc')?>：</td><td align="center"><input type="text" id="name_cn" name="name_cn" readonly></td>
            </tr>
            <tr>
                <td align="right"><?=lang('pcm_sl')?>：</td><td align="center"><input type="text" id="number1" name="number"></td>
            </tr>
            <tr>
                <td align="right"><?=lang('pcm_wxzd')?>：</td><td align="center"><input type="text" id="mt_site" name="mt_site"></td>
            </tr>
            <tr>
                <td align="right"><?=lang('pcm_tjr')?>：</td><td align="center"><input type="text" id="addname" name="addname" value="<?=$this->users['name']?>" readonly></td>
            </tr>
            <tr>
                <td align="right"><?=lang('pcm_cpid')?>：</td><td align="center"><input type="text" id="pid" name="pid" value="<?=$peijianData['pid']?>" readonly></td>
            </tr>
            <tr>
                <td align="right"><?=lang('peijian_jg')?>(USD):</td>
                <td align="center">
                    <input type="hidden" name="wxdh" value="<?=$mtid?>"/>
                    <input type="hidden" name="wid"  />
                    <input type="hidden" name="accessory_cost" />
                    <input type="text" name="accessory_price"  readonly />
                </td>
            </tr>
        </table>
    </form>
    </div>
    <div id="mjieguo" style="margin:0px auto; margin-top: 10px; width: 350px; height: 300px; display: none">
        <h1><?=lang('pcm_zbdpj')?></h1>
        <form action="<?=blang_url('products/material/addmaterial/'.$peijianData['pid'].'/'.$mtid)?>" method="post" id="caigou2" name="caigou2">
            <table style="width: 300px;height: 250px;" border="0">
                <tr>
                    <td align="right"><?=lang('pcm_pingpai')?>：</td><td align="center"><input type="text" id="pingpai" name="pingpai"></td>
                </tr>
                <tr>
                    <td align="right"><?=lang('pcm_xinghao')?>：</td><td align="center"><input type="text" id="xinghao" name="xinghao"></td>
                </tr>
                <tr>
                    <td align="right"><?=lang('pcm_yanse')?>：</td><td align="center"><input type="text" id="yanse" name="yanse"></td>
                </tr>
            <tr>
                <td align="right"><?=lang('peijian_pjmc')?>：</td><td align="center"><input type="hidden" id="mt_site" name="mt_site" value="<?=substr($mtid,0,2)?>"><input type="text" id="name_cn" name="name_cn"></td>
            </tr>
            <tr>
                <td align="right"><?=lang('pcm_sl')?>：</td><td align="center"><input type="hidden" id="addname" name="addname" value="<?=$this->users['name']?>"><input type="text" id="number2" name="number"></td>
            </tr>
                <tr>
                    <td align="right"><?=lang('peijian_jg')?>(USD):</td>
                    <td align="center">
                        <input type="hidden" name="wxdh" value="<?=$mtid?>"/>
                        <input type="hidden" name="wid"  />
                        <input type="hidden" name="accessory_cost"  readonly />
                        <input type="text" name="accessory_price"  readonly />
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div id="embedding">
        <a href="javascript:void(0)" id="tanchu"><?=lang('pcm_qd')?></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" id="tanchu"><?=lang('pcm_qx')?></a>
    </div>
</div>
